<?php
/*
	首页
*/
//cfc('core')->checklogin();
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
set_html('header','common/header-cms');
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['indexpai']=array();
	$setting = $this->plugin_setting('setting');
	if(!$setting['issearch']){
		$return['indexpai'][]=array('name'=>'search');
	}
	if(!$setting['ishdps']){
		$return['indexpai'][]=array('name'=>'hdps');
	}
	if(!$setting['iscube']){
		$return['indexpai'][]=array('name'=>'cube');
	}
	if(!$setting['isshare']){
		$return['indexpai'][]=array('name'=>'share');
	}
	$return['indexpai'][]=array('name'=>'coupon');
	$return['indexpai'][]=array('name'=>'goods');
	//公告列表
	$notice_list = pdo_fetchall('SELECT * FROM ' . tablename('jy_weishop_notice') . ' WHERE uniacid=:uniacid AND status=1  ORDER BY id DESC limit 4', array(':uniacid' => $_SESSION['uniacid']));
	if($notice_list){
		foreach($notice_list as &$notice){
			$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
		}
	}
	$brand = pdo_getall('jy_weishop_goods_brand', array('uniacid' =>$_SESSION['uniacid'],'isshow'=>1));
	$return['brand']=$brand;
	//获取用户信息
	$return['extradata']=array();
	//$return['user']=model('core/member')->basic($_SESSION['uid']);
	$return['login']=$_SESSION['uid']?1:2;
	$return['params']=array();
	$return['notice_list']=$notice_list;
	$return['p_group']=$p_group;
	set_html('title',$setting['title']?'首页-'.$setting['title']:'首页-品牌馆');
	$return['sharedata']=array(
		'title'=>$setting['share_title']?$setting['share_title']:'首页-品牌馆',
		'desc'=>$setting['share_desc']?$setting['share_desc']:'品牌馆，一个属于自己的个人商城！',
		'link'=>custom_url('jy_weishop/index//fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
	);
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1);
	if($_RQ['brandid']){
		$params['id']=$_RQ['brandid'];
		$return['params']['brandid']=$_RQ['brandid'];
	}
	$brand=pdo_getall('jy_weishop_goods_brand',$params);	
	$goodsids=array();
	foreach($brand as $bv){
		$bv['goods']=json_decode($bv['goods'],true);
		foreach($bv['goods'] as &$gv){
			$goodsids[]=$gv['id'];
		}
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if(count($goodsids)){
		$params['id']=$goodsids;
	}else{
		$params['id']=0;
	}
	if(trim($_RQ['keyword'])){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
		$return['params']['keyword']=trim($_RQ['keyword']);
	}
    $orderby='id desc';
	$total='';
	$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($list as &$v){
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
	}
	$return['list']=$list;
	exi($return);
}
function style($id)
{
	switch ($id%7) {	
		case 0: return "style-brown";
		case 1: return 'style-red';
		case 2: return "style-pink";
		case 3: return "style-orange";
		case 4: return "style-green";
		case 5: return "style-blue";
		case 6: return "style-purple";
		case 7: return "style-brown";
		default: }
}
	
?>